<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>h5 video</title>
  <style>
    body {
      background-color: #fff;
      text-align: center;
    }

    .container {
      position: relative
    }

    #ad,
    #ctrl {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }

    #ad {
      width: 400px;
      height: 300px;
    }

    #ctrl img {
      width: 120px;
      height: 120px;
    }
  </style>
</head>

<body>
  <div class="container">
    <!-- 视频区域 -->
    <video id="v1" preload="auto" controls src="res/angrybirds.mp4">
      你的浏览器版本太低,请升级!
    </video>
    <!-- 广告区域 -->
    <img src="res/1.jpg" id="ad">
    <!-- 按钮区域 -->
    <a href="#" id="ctrl">
      <img src="res/Play.png" alt="">
    </a>
    <p><button onclick="quanping()">全屏</button></p>
    <p><button onclick="quite()">退出全屏</button></p>
  </div>

  <script>
    var container = document.querySelector(".container");
    var video = document.getElementById("v1");
    var ctrl = document.getElementById("ctrl");
    var ad = document.getElementById("ad");
    var imgplay = document.querySelector("#ctrl img");
    video.volume = 0.8; //音量初始值
    // video.playbackRate = 5;  //播放速度

    // 鼠标移入 显示播放按钮
    container.onmouseenter = function () {
      ctrl.style.display = "block";
    }
    // 鼠标移入 隐藏播放按钮
    container.onmouseleave = function () {
      ctrl.style.display = "none";
    }
    console.log("video:", video.paused);
    ctrl.onclick = function (event) {
      event.preventDefault(); // 阻止默认行为

      if (video.paused) {
        video.play();
        imgplay.src = "res/Pause.png";
        ad.style.display = "none";
      } else {
        video.pause();
        imgplay.src = "res/Play.png";
        ad.style.display = "block";
      }

      // ctrl.style.display = "none";
    }
    function quanping() {
      video.requestFullscreen();
    }
    function quite() {
      video.exitFullscreen()
    }
  </script>
</body>

</html>